package cn.ffcs.uec.insurance.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.ListModelList;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.uec.insurance.action.bean.UecBmclassListMainBean;
import cn.ffcs.uec.insurance.manager.UecBmManager;
import cn.ffcs.uec.insurance.model.UecBmclass;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.NumericUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Controller
@Scope("prototype")
public class UecBmclassListMainComposer extends BasePortletComposer {

	private static final long serialVersionUID = -2497274555244653652L;

	private UecBmclassListMainBean bean = new UecBmclassListMainBean();

	private UecBmclass qryUecBmclass;
	
	private UecBmManager uecBmManager = (UecBmManager) ApplicationContextUtil
			.getBean("uecBmManager");

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);
	}
	/**
	 * 初始化
	 */
	public void onCreate$uecBmclassListMainWin() {
		this.bindBean();
		this.onQueryUecBmclass();
	}
	/**
	 * 选择查询记录
	 * 
	 * @throws Exception
	 */
	public void onSelectRequest() throws Exception {
		if (this.bean.getUecBmclassListbox().getSelectedCount() > 0) {
			qryUecBmclass = (UecBmclass) bean.getUecBmclassListbox()
					.getSelectedItem().getValue();
			Events.postEvent("onOK", this.self, qryUecBmclass);
			this.onCancel();
		}
	}
	/**
	 * bindBean
	 */
	public void bindBean() {
		this.bean.getUecBmclassListMainWin().setTitle("险种选择列表");
		qryUecBmclass = (UecBmclass) arg.get("qryUecBmclass");
		if (null != qryUecBmclass) {
		}
	}

	/**
	 * 取消
	 */
	public void onCancel() {
		this.bean.getUecBmclassListMainWin().onClose();
	}
	/**
	 * 查询
	 */
	public void onQueryUecBmclass() {
		if (null != qryUecBmclass) {
			int activePage = bean.getUecBmclassListboxPaging().getActivePage();
			int pageSize = bean.getUecBmclassListboxPaging().getPageSize();
			PageInfo pageInfo = uecBmManager
					.queryPageInfoByUecBmclass(qryUecBmclass, activePage + 1,
							pageSize);
			ListModelList dataList = new BindingListModelList(
					pageInfo.getDataList(), true);
			bean.getUecBmclassListbox().setModel(dataList);
			bean.getUecBmclassListboxPaging().setTotalSize(
					NumericUtil.nullToZero(pageInfo.getTotalCount()));
		}

	}
	/**
	 * 翻页
	 */
	public void onUecBmclassListboxPaging() {
		this.onQueryUecBmclass();
	}

}
